package com.tengju.bff.interfaces.manage.crm.crowd.assembler;

import com.tengju.bff.interfaces.manage.crm.crowd.vo.CrowdListForm;
import com.tengju.data.domain.model.cqrs.CrowdListFormQO;
import com.tengju.data.domain.shared.Month;
import com.tengju.data.domain.shared.Quarter;
import com.tengju.user.domain.model.user.UserIdCode;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author chenhang
 * @Date 2021/5/8
 */
public class CrowdAssembler {
    public static CrowdListFormQO toQO(List<UserIdCode> genSecIdCodes, CrowdListForm form) {
        //生成上月、本月、上季度的月份数据
        LocalDate now = LocalDate.now();
        Month curMonth = new Month(now);
        Month lastMonth = curMonth.preMonth();
        Quarter quarter = new Quarter(LocalDate.now());
        List<Month> queryMonth = new ArrayList<>();
        List<Month> months = quarter.listMonthUntilDay(LocalDate.now());
        queryMonth.add(lastMonth);
        queryMonth.addAll(months);

        if (form == null) {
            return null;
        }
        return new CrowdListFormQO(
                genSecIdCodes,
                form.getIdCode(),
                form.getBelongGenSecIdCode(),
                form.getBelongEcIdCode(),
                form.getBelongServiceProviderIdCode(),
                form.isDirect(),
                form.getTagName(),
                form.getTagValue(),
                form.getOrderColumn(),
                form.getOrderType(),
                form.getOffset(),
                form.getPageSize(),
                curMonth,
                lastMonth,
                queryMonth
        );
    }
}
